/*    
    OpenMheg - A free MHEG-5 library
    Copyright (C) 2008 Dharmesh Malam

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;

namespace Core.Model.Data.Type
{
    public class ContentRef
    {
        #region internal Attributes

        private String value;

        private int contentSize;

        public int ContentSize
        {
            get { return contentSize; }
            set { contentSize = value; }
        }
        private int contentCachePriority;

        public int ContentCachePriority
        {
            get { return contentCachePriority; }
            set { contentCachePriority = value; }
        }

        #endregion

        #region Constructors

        public ContentRef () { }

        public ContentRef ( String value )
        {
            this.Value = value;
        }

        public ContentRef(OctetString value)
        {
            this.Value = value.ToString();
        }

        public ContentRef ( String value, int contentSize, int contentCachePriority )
        {
            this.Value = value;
            this.ContentSize = contentSize;
            this.ContentCachePriority = contentCachePriority;

        }
        #endregion

        #region Actions

        public string Value
        {
            get { return this.value; }
            set
            {
                if ( value.StartsWith( "~" ) )
                    this.value = value.Remove( 0, 1 );
                else
                    this.value = value;
            }
        }

        public override bool Equals ( Object o )
        {
            if ( this == o ) return true;
            if ( !( o is ContentRef ) ) return false;

            //ContentRef contentRef = ( ContentRef ) o;

            return Value == ( ( ContentRef ) o ).Value;

            //if ( value != null ? !value.Equals( contentRef.value ) : contentRef.value != null ) return false;

            //return true;
        }

        public override int GetHashCode ()
        {
            return ( value != null ? value.GetHashCode(): 0 );
        }

        public override String ToString ()
        {
            return ( value != null ? value.ToString(): "" );
        }
        #endregion
    }
}
